$(function () {
  var body = document.getElementsByTagName('body')[0];
  if (body.id === 'diagnosisBody') {
    /*初始化视频*/
    var $childMenuList = $('#childMenu li');             // 二级导航按钮
    var $liA = $('#childMenu li a');                    // 二级导航按钮的a标签
    var number_one = $('#startProject').text() / 1;
    var number_two = $('#cooperation').text() / 1;
    var number_three = $('#publishArticle').text() / 1;
    var flag = true;

    // 给swiper绑定change插件
    mySwiper.on('slideChange', function () {
      // 页面切换后执行
      var $menuName = $('#menuName');
      // 根据不同的index，更换不同的menu的名字
      $menuName.html($liA[this.activeIndex].text);
    });
    /*荣誉资质图片轮播*/
    var researchSwiper = new Swiper('.researchSwiper', {
      direction: 'horizontal',
      loop: true,
      autoplay: {
        delay: 5000,
        stopOnLastSlide: false,
        disableOnInteraction: true,
      },
      // 响应鼠标滚轮
      mousewheel: false,

      // 将宽和高取整，防止某些情况下边界模糊
      roundLengths: true,

      //分页器
      pagination: {
        /*选择分页器*/
        el: '.swiper-pagination',

        /*可点击*/
        clickable: true,

        /*自定义样式*/
        type: 'custom',

        /*自定义样式*/
        renderCustom: function (swiper, current, total) {
          var paginationHtml = "";
          for (var i = 0; i < total; i++) {
            // 判断是不是激活焦点，是的话添加active类，不是就只添加基本样式类
            if (i === (current - 1)) {
              paginationHtml += '<span class="swiper-pagination-bullet swiper-pagination-bullet-activ">&nbsp;</span>';
            } else {
              paginationHtml += '<span class="swiper-pagination-bullet">&nbsp;</span>';
            }
          }
          return paginationHtml;
        },
      },
      lazy: true,
    });

    mySwiper.on('slideChange', function () {
      var i = 0;
      var j = 0;
      var k = 0;
      //实现动态加载数字

      if (this.activeIndex == 9 && flag) {

        $('#startProject').html('0');
        $('#cooperation').html('0');
        $('#publishArticle').html('0');
        var oneInterval = setInterval(assignone, 50);
        var twoInterval = setInterval(assigntwo, 50);
        var threeInterval = setInterval(assignthree, 50);
        flag = false;

        function assignone() {
          if (i != number_one) {
            i++;
            $('#startProject').html(i);
          } else {
            flag = !flag;
            clearInterval(oneInterval);
          }
        }

        function assigntwo() {
          if (j != number_two) {
            j++;
            $('#cooperation').html(j);
          } else {
            clearInterval(twoInterval);
          }
        }

        function assignthree() {
          if (k != number_three) {
            k++;
            $('#publishArticle').html(k);
          } else {
            clearInterval(threeInterval);
          }
        }
      }
    });


    /*二级导航滚屏*/
    for (var i = 0; i < $childMenuList.length; i++) {
      $childMenuList[i].index = i;
      $childMenuList[i].onclick = function () {
        mySwiper.slideTo(this.index, 1000, false);  //切换到第一个slide，速度为1秒
      }
    }
  }
});
